package com.shizhanzhe.gxb.vip.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.shizhanzhe.gxb.R;
import com.shizhanzhe.gxb.brand.bean.Theme;

import java.util.List;

/**
 * Created by zz9527 on 2019/1/9.
 */
public class StatisticsAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private Context mContext;
    private List<Theme.DataBean> list;

    public StatisticsAdapter(Context context, List<Theme.DataBean> list) {
        this.list = list;
        this.mContext = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.adapter_statistics, null);
            holder = new ViewHolder();
            holder.img = convertView.findViewById(R.id.iv);
            holder.nickname = convertView.findViewById(R.id.nickname);
            holder.money = convertView.findViewById(R.id.money);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Theme.DataBean bean = list.get(i);
        Glide.with(mContext).load(bean.getImage_url()).apply(new RequestOptions().error(R.mipmap.logo)).into(holder.img);
        holder.nickname.setText(bean.getName());
        holder.money.setText(bean.getGoods_num()+"元");
        return convertView;
    }

    private static class ViewHolder {
        ImageView img;
        TextView nickname;
        TextView money;
    }
}
